<template>
    <div>
        <!-- seach区域 -->
        <div class="seach">
            <span class="seachStatus">
                {{$t('tsknum')}}
                <el-input v-model.trim="frozenTask.orderNo" :placeholder="$t('plsipt')" size="mini"></el-input>
            </span>
            <span class="seachCsc">
                {{$t('subttim')}}
                <el-date-picker :placeholder="$t('plsset')" v-model="auditTime" width="20%" type="daterange" :range-separator="$t('to')" :start-placeholder="$t('startdate')" :end-placeholder="$t('dateclosed')" format="yyyy-MM-dd" value-format="yyyy-MM-dd" size="mini"></el-date-picker>
            </span>
            <span class="seachStatus">
                {{$t('audsta')}}
                <el-select v-model="frozenTask.auditStatus" :placeholder="$t('plsset')" size="mini">
                    <el-option :label="'-' + $t('plsset') + '-'" :value="null"></el-option>
                    <el-option :label="$t('tobeaud')" value="WAITCONFIRM"></el-option>
                    <el-option :label="$t('passed')" value="SUCCESS"></el-option>
                    <el-option :label="$t('reject')" value="REJECT"></el-option>
                </el-select>
            </span>
             <span class="seachStatus">
                {{$t('mertid')}}
                <el-input v-model.trim="frozenTask.merId" :placeholder="$t('plsipt')" size="mini"></el-input>
            </span>
            <el-button type="primary" @click="seachTask" size="mini" v-preventReClick>{{$t('qury')}}</el-button>
        </div>
        <!-- 内容区域 -->
        <el-card class="cardBox">
            <el-table border style="width: 100%" :data="taskList">
                <el-table-column type="index" :label="$t('sernum')">
                </el-table-column>
                <el-table-column prop="orderNo" :label="$t('apptskno')" min-width="164">
                </el-table-column>
                <el-table-column prop="applyType" :label="$t('tsktpy')" min-width="145">
                </el-table-column>
                <el-table-column prop="merId" :label="$t('mertid')" min-width="163">
                </el-table-column>
                <el-table-column prop="auditUserName" :label="$t('audr')">
                </el-table-column>
                <el-table-column prop="auditStatus" :label="$t('audsta')" min-width="130">
                </el-table-column>
                <el-table-column prop="applyTime" :label="$t('subttim')" min-width="145">
                </el-table-column>
                <el-table-column prop="address" :label="$t('opratn')" width="90" fixed="right">
                    <template slot-scope="scope">
                        <el-link type="primary" @click="showaudit(scope.row)" v-if="scope.row.auditStatus === $t('tobeaud')">{{$t('exme')}}</el-link>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="frozenTask.pageNum"
                :page-sizes="[10, 15, 20, 30]"
                :page-size="frozenTask.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :pager-count="5">
            </el-pagination>
        </el-card>
        <!-- 审核弹框 -->
        <el-dialog :title="$t('freunacc')" :visible.sync="auditDialogVisible" width="30%" @close="auditDialogVisibleClosed(auditFrozenForm)" :close-on-click-modal='isOk' :modal-append-to-body="false">
            <el-form :ref="auditFrozenForm" :model="auditFrozenForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item :label="$t('remk')" prop="auditRemark" :placeholder="$t('plsipt')">
                    <el-input type="textarea" v-model="auditFrozenForm.auditRemark"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="auditNan('SUCCESS')" v-preventReClick>{{$t('passed')}}</el-button>
                <el-button type="warning" @click="auditNan('REJECT')" v-preventReClick>{{$t('reject')}}</el-button>
                <el-button @click="auditDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
            </span>
        </el-dialog>
        <!-- 修改弹框 -->
        <!-- <el-dialog title="修改" :visible.sync="editDialogVisible" width="30%" @close="editDialogVisibleClosed(editRoleForm)" :close-on-click-modal='isOk'>
            <el-form :ref="editRoleForm" :rules="editRoleRul" :model="editRoleForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item label="角色名" prop="roleName">
                    <el-input v-model="editRoleForm.roleName"></el-input>
                </el-form-item>
                <el-form-item label="角色值" prop="roleCode">
                    <el-input v-model="editRoleForm.roleCode"></el-input>
                </el-form-item>
                <el-form-item label="状态" prop="status">
                    <el-select v-model="editRoleForm.status">
                        <el-option label="生效" value="生效"></el-option>
                        <el-option label="失效" value="失效"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="editRole(addRoleForm)">确 定</el-button>
                <el-button @click="editDialogVisible = false">取 消</el-button>
            </span>
        </el-dialog> -->
    </div>
</template>

<script>
import {
    freuserlist,
    auditrecfrozen
} from '@/libs/reqlist.js'
import { getInitDate } from '@/libs/getDate.js'
export default {
    data () {
        return {
            applytime: null,
            isOk: false,
            total: 0,
            frozenTask: {
                orderNo: null,
                auditStatus: 'WAITCONFIRM',
                name: null,
                startTime: null,
                endTime: null,
                merId: null,
                orderParamIdx: 0,
                orderType: null,
                applyTypeList: [
                    'MER_FROZEN',
                    'MER_UNFROZEN'
                ],
                pageNum: 1,
                pageSize: 10
            },
            auditFrozenForm: {
                appType: null,
                auditRemark: null,
                auditStatus: null,
                orderNo: null,
                parentAuditId: null,
                parentOrderNo: null
            },
            taskList: [],
            auditDialogVisible: false,
            taskForm: {},
            auditTime: null
        }
    },
    methods: {
        getFreezeList () {
            freuserlist(JSON.stringify(this.frozenTask)).then(res => {
                if (res.data.code === '000000') {
                    this.taskList = res.data.data.list
                    this.total = res.data.data.total - 0
                    this.taskList.forEach(item => {
                        if (item.auditStatus === 'WAITCONFIRM') item.auditStatus = this.$t('tobeaud')
                        if (item.auditStatus === 'SUCCESS') item.auditStatus = this.$t('passed')
                        if (item.auditStatus === 'REJECT') item.auditStatus = this.$t('reject')
                        if (item.applyType === 'MER_FROZEN') item.applyType = this.$t('mertofre')
                        if (item.applyType === 'MER_UNFROZEN') item.applyType = this.$t('mertothaw')
                    })
                }
            })
        },
        handleSizeChange (newSize) {
            this.frozenTask.pageSize = newSize
            this.getFreezeList()
        },
        // 监听总页数变化
        handleCurrentChange (newNum) {
            this.frozenTask.pageNum = newNum
            this.getFreezeList()
        },
        seachTask () {
            if (this.auditTime !== null) {
                this.frozenTask.startTime = this.auditTime[0] + ' 00:00:00'
                this.frozenTask.endTime = this.auditTime[1] + ' 59:59:59'
            }
            if (!this.auditTime) {
                this.frozenTask.startTime = null
                this.frozenTask.endTime = null
            }
            this.frozenTask.pageNum = 1
            this.getFreezeList()
        },
        orderDetails (no) {
            this.$store.commit('handleOrderNo', no)
            this.$router.push('/orderDetailsForm')
        },
        showaudit (data) {
            this.auditFrozenForm.appType = data.applyType
            this.auditFrozenForm.orderNo = data.orderNo
            this.auditDialogVisible = true
        },
        auditNan (state) {
            this.auditFrozenForm.auditStatus = state
            if (this.auditFrozenForm.auditRemark) this.auditFrozenForm.auditRemark = this.auditFrozenForm.auditRemark.trim()
            auditrecfrozen(JSON.stringify(this.auditFrozenForm)).then(res => {
                if (res.data.code === '000000') {
                    this.$message({
                        message: this.$t('audcomp'),
                        type: 'success'
                    })
                    this.auditDialogVisible = false
                    this.getFreezeList()
                }
            })
        },
        auditDialogVisibleClosed (form) {
            this.$refs[form].resetFields()
        }
    },
    mounted () {
        this.getFreezeList()
    }
}
</script>

<style lang="less" scoped>
@import './ramAccAud.less';
</style>
